<?php

namespace app\api\controller;


use app\api\model\house\HouseOrderComplain;
use app\api\model\house\HouseOrderComplain as HouseOrderComplainModel;
use app\api\model\house\HouseOrderComplainReply;
use app\common\controller\Api;


class Housecomplain extends Api
{
    protected $noNeedRight = ['*'];


    //我的投诉-房屋订单
    public function myHouseComplain()
    {
        $list = HouseOrderComplain::where(['user_id'=>$this->auth->id])
            ->order('createtime desc')
            ->paginate(10, false, ['query' => request()->get()]);
        $this->success('',$list);
    }

    //用户回复-房屋订单
    public function userReplyComplain()
    {
        $complain_id = input('complain_id',0);
        $content = input('content','');
        $images = input('images','');
        $is_solve = input('is_solve',0);
        $info = HouseOrderComplain::get($complain_id);
        if (!$info)$this->error('投诉不存在');
        if (!$content)$this->error('请输入补充说明');
        $res = HouseOrderComplainReply::add($complain_id,$this->auth->id,'user',$content,$images,$is_solve);
        $this->success('',$res);
    }


    //我收到的投诉-房屋订单
    public function myReceiveHouseComplain()
    {
        $list = HouseOrderComplain::where(['owner_id'=>$this->auth->id])
            ->order('createtime desc')
            ->paginate(10, false, ['query' => request()->get()]);
        $this->success('',$list);
    }

    //业主回复/反馈-房屋订单
    public function ownerReplyComplain()
    {
        $complain_id = input('complain_id',0);
        $content = input('content','');
        $images = input('images','');
        $info = HouseOrderComplain::get($complain_id);

        if (!$info)$this->error('投诉不存在');
        if (!$content)$this->error('请输入补充说明');
        $res = HouseOrderComplainReply::add($complain_id,$this->auth->id,'owner',$content,$images);
        $this->success('',$res);
    }


    //详情
    public function info()
    {
        $complain_id = input('complain_id',0);
        $model = new HouseOrderComplainModel();

        $info = $model->info($complain_id);
        $this->success('提交成功',$info);
    }

    //删除
    public function del()
    {
        $complain_id = input('complain_id',0);
        $info = HouseOrderComplain::get($complain_id);
        $info->delete();
        $this->success('删除成功');
    }
}